package com.mes.task.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.springframework.context.annotation.Lazy;

import com.mes.basicdata.domain.Dept;
import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.Part;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;
import com.mes.inventory.domain.Warehouse;


 
/**
 * <p>
 * ShopOrder实体，代表车间计划指令，相当于系统缺件清单
 *  </p>
 * author lcs
 * data 2017-03-18
 */
@Entity()
//@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name = "T_DEMAND")
//省略SQL语句："demandtype like '600'"
@Lazy(value=true)
//@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class WorkOrder extends BasicModel {

	public final static int WORKORDERSTATE_FINISHED = 2; //已完成
	public final static int WORKORDERSTATE_DRAFT= 0; //草稿
	public final static int WORKORDERSTATE_STARTED = 1; //已下达
	
	@Id
	@GenericGenerator(name = "memandUid", strategy = "assigned")
	@Column(name="DEMANDUID",length=50)
	private String memandUid;
	
	@Override
	public String getUuid() {
		return memandUid;
	}

	@Override
	public void setUuid(String uuid) {
		this.memandUid = uuid;
	}
	
	public String getMemandUid() {
		return memandUid;
	}

	public void setMemandUid(String memandUid) {
		this.memandUid = memandUid;
	}



	//protected Set<Demand> demands;
	/**
	 * 缺件表编号
	 */
	@Column(name="DEMANDID")
	protected String workOrderId;
	
	@Column(name="MODEL")
	protected String model;
	
	@Column(name="BATCHNUM")
	protected String batchNum;
	/*
	 * 物料编号
	 */
	@Column(name="PART_NUMBER")
	protected String partUid;
	/**
	 * 物料对象
	 * 复杂对象映射--part
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PART_NUMBER",insertable=false,updatable=false)
	protected Part part;
	/*
	 * 缺件数量，净需求数量
	 */
	@Column(name="DUEQTY",precision=25,scale=6)
	protected Double dueQty;
	
	@Column(name="EARLYSTART",length=7)
	protected Date earlyStart;
	
	@Column(name="EARLYFINISH",length=7)
	protected Date earlyFinish;
	
	@Column(name="LATESTART",length=7)
	protected Date lateStart;
	/*
	 * 最晚交货时间，交货期
	 * 
	 */
	@Column(name="LATEFINISH",length=7)
	protected Date lateFinish;
	
	@Column(name="ACTUALSTART",length=7)
	protected Date actualStart;
	
	@Column(name="ACTUALFINISH",length=7)
	protected Date actualFinish;
	/**
	 * 类型与状态映射--priority
	 */
	@Column(name="PRIORITY")
	protected Integer priority;
	
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="PRIORITY",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'prio'", referencedColumnName="TYPESNAME"))
	})
	protected TypesData priorityDesc;
	
	@Column(name="COMPLETEPERCENT",precision=25,scale=6)
	protected Double completePercent;

	@Column(name="SUSPENDED",precision=2,scale=0)
	protected Boolean suspended;
	
	@Column(name="SHRINKQTY",precision=25,scale=6)
	protected Double shrinkQty;
	
	@Column(name="DELIVERYQTY",precision=25,scale=6)
	protected Double deliveryQty;

	@Column(name="DEMANDSTATE",precision=2,scale=0)
	protected Integer workOrderState;
	
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="DEMANDSTATE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'demandstate'", referencedColumnName="TYPESNAME"))
	})
	protected TypesData workOrderStateDesc;
	
	@Column(name="DEPTID")
	protected String deptUid;
	/**
	 * 复杂对象映射--dept
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="DEPTID",insertable=false,updatable=false)
	protected Dept dept;
	/*
	 * 主制部门编号
	 */
	@Column(name="MASTERSHOP")
	protected String masterShopUid;
	/**
	 * 复杂对象映射--mastershop
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="MASTERSHOP",insertable=false,updatable=false)
	protected Dept masterShop;

	/**
	 * 类型与状态映射--routinestate
	 */
	@Transient
	protected Integer routineState;
	
	@Transient
	protected TypesData routineStateDesc;

	/**
	 * 类型与状态映射--materialstate
	 * 
	 */
	@Transient
	protected Integer materialState;
	
	@Transient
	protected TypesData materialStateDesc;

	/**
	 * 类型与状态映射--resourcestate
	 */
	@Transient
	protected Integer resourceState;
	@Transient
	protected TypesData resourceStateDesc;

	@Column(name="WAREHOUSEID",length=50)
	protected String wareHouseUid;
	/**
	 * 复杂对象映射--warehouse
	 */
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="WAREHOUSEID",insertable=false,updatable=false)
	protected Warehouse wareHouse;

	@Transient
	protected Integer responseTime;


	/**
	 * 类型与状态映射--Demandtype
	 */
	@Column(name="DEMANDTYPE",length=50)
	protected String workOrderType;
	
	//many-to-one
	@ForeignKey(name="null")
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumnsOrFormulas(value={
			@JoinColumnOrFormula(column=@JoinColumn(name="DEMANDTYPE",referencedColumnName="ID",nullable=true,insertable=false,updatable=false)),
			@JoinColumnOrFormula(formula=@JoinFormula(value="'demandtype'", referencedColumnName="TYPESNAME"))
	})
	protected TypesData workOrderTypeDesc;
	
	/*
	 * 该指令是否分解
	 */
	@Column(name="ISBREAK")
	protected Boolean isBreak;
	
/*	protected String parentWorkOrderUid;
	protected WorkOrder parentWorkOrder;*/

	public Boolean getIsBreak() {
		return isBreak;
	}

	public void setIsBreak(Boolean isBreak) {
		this.isBreak = isBreak;
	}

	/** default constructor */
	public WorkOrder() {
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getBatchNum() {
		return batchNum;
	}

	public void setBatchNum(String batchNum) {
		this.batchNum = batchNum;
	}

	public String getPartUid() {
		return partUid;
	}

	public void setPartUid(String partUid) {
		this.partUid = partUid;
	}

	public Part getPart() {
		return part;
	}

	public void setPart(Part part) {
		this.part = part;
	}

	public Double getDueQty() {
		return dueQty;
	}

	public void setDueQty(Double dueQty) {
		this.dueQty = dueQty;
	}

	public Date getEarlyStart() {
		return earlyStart;
	}

	public void setEarlyStart(Date earlyStart) {
		this.earlyStart = earlyStart;
	}

	public Date getEarlyFinish() {
		return earlyFinish;
	}

	public void setEarlyFinish(Date earlyFinish) {
		this.earlyFinish = earlyFinish;
	}

	public Date getLateStart() {
		return lateStart;
	}

	public void setLateStart(Date lateStart) {
		this.lateStart = lateStart;
	}

	public Date getLateFinish() {
		return lateFinish;
	}

	public void setLateFinish(Date lateFinish) {
		this.lateFinish = lateFinish;
	}

	public Date getActualStart() {
		return actualStart;
	}

	public void setActualStart(Date actualStart) {
		this.actualStart = actualStart;
	}

	public Date getActualFinish() {
		return actualFinish;
	}

	public void setActualFinish(Date actualFinish) {
		this.actualFinish = actualFinish;
	}

	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	public TypesData getPriorityDesc() {
		return priorityDesc;
	}

	public void setPriorityDesc(TypesData priorityDesc) {
		this.priorityDesc = priorityDesc;
	}

	public Double getCompletePercent() {
		return completePercent;
	}

	public void setCompletePercent(Double completePercent) {
		this.completePercent = completePercent;
	}

	public Boolean getSuspended() {
		return suspended;
	}

	public void setSuspended(Boolean suspended) {
		this.suspended = suspended;
	}

	public Double getShrinkQty() {
		return shrinkQty;
	}

	public void setShrinkQty(Double shrinkQty) {
		this.shrinkQty = shrinkQty;
	}

	public Double getDeliveryQty() {
		return deliveryQty;
	}

	public void setDeliveryQty(Double deliveryQty) {
		this.deliveryQty = deliveryQty;
	}

	public String getDeptUid() {
		return deptUid;
	}

	public void setDeptUid(String deptUid) {
		this.deptUid = deptUid;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public String getMasterShopUid() {
		return masterShopUid;
	}

	public void setMasterShopUid(String masterShopUid) {
		this.masterShopUid = masterShopUid;
	}

	public Dept getMasterShop() {
		return masterShop;
	}

	public void setMasterShop(Dept masterShop) {
		this.masterShop = masterShop;
	}

	public Integer getRoutineState() {
		return routineState;
	}

	public void setRoutineState(Integer routineState) {
		this.routineState = routineState;
	}

	public TypesData getRoutineStateDesc() {
		return routineStateDesc;
	}

	public void setRoutineStateDesc(TypesData routineStateDesc) {
		this.routineStateDesc = routineStateDesc;
	}

	public Integer getMaterialState() {
		return materialState;
	}

	public void setMaterialState(Integer materialState) {
		this.materialState = materialState;
	}

	public TypesData getMaterialStateDesc() {
		return materialStateDesc;
	}

	public void setMaterialStateDesc(TypesData materialStateDesc) {
		this.materialStateDesc = materialStateDesc;
	}

	public Integer getResourceState() {
		return resourceState;
	}

	public void setResourceState(Integer resourceState) {
		this.resourceState = resourceState;
	}

	public TypesData getResourceStateDesc() {
		return resourceStateDesc;
	}

	public void setResourceStateDesc(TypesData resourceStateDesc) {
		this.resourceStateDesc = resourceStateDesc;
	}

	public String getWareHouseUid() {
		return wareHouseUid;
	}

	public void setWareHouseUid(String wareHouseUid) {
		this.wareHouseUid = wareHouseUid;
	}

	public Warehouse getWareHouse() {
		return wareHouse;
	}

	public void setWareHouse(Warehouse wareHouse) {
		this.wareHouse = wareHouse;
	}

	public Integer getResponseTime() {
		return responseTime;
	}

	public void setResponseTime(Integer responseTime) {
		this.responseTime = responseTime;
	}

	public Employee getCreator() {
		return creator;
	}

	public void setCreator(Employee creator) {
		this.creator = creator;
	}

	public String getWorkOrderId() {
		return workOrderId;
	}

	public void setWorkOrderId(String workOrderId) {
		this.workOrderId = workOrderId;
	}

	public Integer getWorkOrderState() {
		return workOrderState;
	}

	public void setWorkOrderState(Integer workOrderState) {
		this.workOrderState = workOrderState;
	}

	public TypesData getWorkOrderStateDesc() {
		return workOrderStateDesc;
	}

	public void setWorkOrderStateDesc(TypesData workOrderStateDesc) {
		this.workOrderStateDesc = workOrderStateDesc;
	}

	public String getWorkOrderType() {
		return workOrderType;
	}

	public void setWorkOrderType(String workOrderType) {
		this.workOrderType = workOrderType;
	}

	public TypesData getWorkOrderTypeDesc() {
		return workOrderTypeDesc;
	}

	public void setWorkOrderTypeDesc(TypesData workOrderTypeDesc) {
		this.workOrderTypeDesc = workOrderTypeDesc;
	}

/*	public String getParentWorkOrderUid() {
		return parentWorkOrderUid;
	}

	public void setParentWorkOrderUid(String parentWorkOrderUid) {
		this.parentWorkOrderUid = parentWorkOrderUid;
	}

	public WorkOrder getParentWorkOrder() {
		return parentWorkOrder;
	}

	public void setParentWorkOrder(WorkOrder parentWorkOrder) {
		this.parentWorkOrder = parentWorkOrder;
	}*/
}
